/**
 * Created by Administrator on 2017/9/27.
 */

$(document).ready(function () {

    var allTpl = $('#all-template').html();
    var allCmp = Handlebars.compile(allTpl);
    
    (function () {
        var loading = dialog.loading();
        $.ajax({
            url:C.interface.allCategory,
            type:'get',
            dataType:'json',
            data:{
                lat:C.weidu,
                lng:C.jingdu,
                cityId:C.cityCode
            },
            complete:function () {
                loading.close();
            },
            success:function (response) {
                if (response.errorCode == '200'){
                    var data = response.data;
                    console.log(data)
                    $('#all-box').html(allCmp(data));
                    $('.all-shop-box').each(function (k, v) {
                        var shopList = $(v).find('.all-shop-list');

                        //当数据条数多于12条之后，显示下拉箭头
                        var len = 12;
                        if (shopList.length >len){
                            var lastDom = shopList.eq(len-1);
                            var lastContent = lastDom.html();
                            lastDom.html('<img src="static/img/all_icon_down.png" class="list-more" />').addClass('click-more').nextAll().hide();
                            $('.click-more').click(function () {
                                lastDom.html(lastContent).removeClass('click-more').nextAll().show();
                            })
                        }
                    });

                }else if (response.errorCode == '0'){
                    alert('登录过期请重新登录');
                    againLogin();
                }else {
                    alert(response.errorMsg);
                }
            }
        })
    })();



});